package com.smallA.association.controller;

import com.smallA.association.bo.Result;
import com.smallA.association.constant.UserConstant;
import com.smallA.association.pojo.Association;
import com.smallA.association.pojo.Client;
import com.smallA.association.pojo.Student;
import com.smallA.association.service.AssociationService;
import com.smallA.association.service.UserService;
import com.smallA.association.utils.JwtUtils;
import com.smallA.association.vo.Notice;
import com.smallA.association.vo.RegistrationData;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户注册登录相关服务网络接口层
 *
 * @author wanda
 */
@RestController
public class UserController {

    @Resource
    private UserService userService;
    @Resource
    private AssociationService associationService;

    @RequestMapping("/User/getCode")
    public Result<String> getCode(@RequestBody RegistrationData data) {
        return userService.getCode(data.getEmail());
    }

    @RequestMapping("/User/registeredAssociation")
    public Result<String> registeredAssociation(@RequestBody RegistrationData data) {
        return userService.registeredAssociation(data);
    }

    @Secured(UserConstant.MANAGER_WRITE_ACCESS)
    @RequestMapping("/User/updateUserState")
    public Result<Object> updateUserState(@RequestBody List<Association> list) {
        return userService.updateUserState(list);
    }

    @RequestMapping("/User/exportExcel")
    public Result<Object> exportExcel(@RequestBody List<Student> list) {
        return userService.exportExcel(list);
    }

    @RequestMapping("/User/selectUserByAssociation")
    public Result<Object> selectUserByAssociation(@RequestBody String name) {
        return userService.selectUserByAssociation(JwtUtils.getUser(),name);
    }

//    @RequestMapping("/User/noticeByEmail")
//    public Result<Object> noticeByEmail(@RequestBody List<Student> list,@RequestParam String information) {
//        return userService.noticeByEmail(list,information);
//    }

    @RequestMapping("/User/noticeByEmail")
    public Result<Object> noticeByEmail(@RequestBody Notice notice) {

        return userService.noticeByEmail(notice.getList(),notice.getInformation());
    }

    @RequestMapping("/User/getInformation")
    public Object getInformation() {
        return associationService.selectByUser(JwtUtils.getUser());
    }
}
